﻿using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Xlit.Example.Business.Services;
using Xlit.Project.Entity.Domain;

namespace Xlit.Example.Controllers
{
    /// <summary>
    ///  组织管理
    /// </summary>
    [Route("api/orgnization")]
    public class SysOrgnizationController : Xlit.Project.Mvc.Controller.ControllerBase
    {
        /// <summary>
        /// 组织管理
        /// </summary>
        public SysOrgnizationService sysOrgnizationService { get; set; }

        /// <summary>
        ///  获取组织树
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Get()
        {
            var tree =  sysOrgnizationService.Get();
            return Success(data: tree);
        }

        /// <summary>
        ///  获取组织
        /// </summary>
        /// <param name="id">组织id</param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public IActionResult Get(int id)
        {
            var tree =  sysOrgnizationService.Get(id);
            return Success(data: tree);
        }

        /// <summary>
        ///  更新组织
        /// </summary>
        /// <param name="input">组织</param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Post([FromBody] Sys_Orgnization input)
        {
             sysOrgnizationService.Update(input);
            return Success();
        }

        /// <summary>
        ///  删除组织
        ///  有子组织的不能删除
        /// </summary>
        /// <param name="Id">组织id</param>
        /// <returns></returns>
        [HttpDelete("{Id}")]
        public IActionResult Delete(int Id)
        {
             sysOrgnizationService.Delete(Id);
            return Success();
        }
    }
}